package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func Cors(ctx *gin.Context) {
	ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
	ctx.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
	ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, Token")
	if ctx.Request.Method == http.MethodOptions {
		ctx.AbortWithStatusJSON(200, gin.H{"code": 0, "msg": "ok"})
	}
}
